package com.weiyuwqj.api.util;

import com.weiyuwqj.api.constant.Constants;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

import com.weiyuwqj.api.constant.SmsMessage;

/**
 * Created by TJJ on 16/09/13.
 */
public class Sms {

    public static Object send(String mobile, String content) {
        String password = "";
        try {
            password = MD5.toMD5(Constants.TIANGE_SMS_PWD).toLowerCase();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Map map = new HashMap();
        map.put("uid", Constants.TIANGE_SMS_UID);
        map.put("pwd", password);
        map.put("mobile", mobile);
        map.put("content", Constants.SMSTAIL + content);
        map.put("content", Constants.SMSTAIL + content);
        String result = HttpUtils.URLPost(Constants.SENDSMS_URL, map, "gb2312");
        return SmsMessage.RESULT.get(result);
    }

    public static Object queryMoney() {
        String password = "";
        try {
            password = MD5.toMD5(Constants.TIANGE_SMS_PWD).toLowerCase();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Map map = new HashMap();
        map.put("uid", Constants.TIANGE_SMS_UID);
        map.put("pwd", password);
        map.put("encode", "utf8");
        String result = HttpUtils.URLPost(Constants.QUERYMONEY_URL, map, Constants.UTF_8);
        System.out.println(result);
        if ("100".equals(result.substring(0, result.indexOf('{')))) {
            return result.substring(result.indexOf('}') + 1);
        } else {
            return SmsMessage.RESULT.get(result);
        }
    }


}
